#include "../Shared/Sample.h"

using namespace noise;

void RunSample()
{
	CreateContext( 800, 600, RENDER_COLOR_TEXTURE );
	
	// Primary granite texture.  This generates the "roughness" of the texture
	// when lit by a light source.
	module::Billow primaryGranite;
	primaryGranite.SetSeed (0);
	primaryGranite.SetFrequency (8.0);
	primaryGranite.SetPersistence (0.625);
	primaryGranite.SetLacunarity (2.18359375);
	primaryGranite.SetOctaveCount (6);
	primaryGranite.SetNoiseQuality (QUALITY_STD);

	// Use Voronoi polygons to produce the small grains for the granite texture.
	module::Voronoi baseGrains;
	baseGrains.SetSeed (1);
	baseGrains.SetFrequency (16.0);
	baseGrains.EnableDistance (true);

	// Scale the small grain values so that they may be added to the base
	// granite texture.  Voronoi polygons normally generate pits, so apply a
	// negative scaling factor to produce bumps instead.
	module::ScaleBias scaledGrains;
	scaledGrains.SetSourceModule (0, baseGrains);
	scaledGrains.SetScale (-0.5);
	scaledGrains.SetBias (0.0);

	// Combine the primary granite texture with the small grain texture.
	module::Add combinedGranite;
	combinedGranite.SetSourceModule (0, primaryGranite);
	combinedGranite.SetSourceModule (1, scaledGrains);

	// Finally, perturb the granite texture to add realism.
	module::Turbulence finalGranite;
	finalGranite.SetSourceModule (0, combinedGranite);
	finalGranite.SetSeed (2);
	finalGranite.SetFrequency (4.0);
	finalGranite.SetPower (1.0 / 8.0);
	finalGranite.SetRoughness (6);

	
	// Create a gray granite palette.  Black and pink appear at either ends of
	// the palette; those colors provide the charactistic black and pink flecks
	// in granite.
	utils::Gradient renderer;
	renderer.SetSourceModule (0, finalGranite);
	renderer.ClearGradient ();
	//*
	renderer.AddGradientPoint (-1.0000, utils::Color (  0,   0,   0, 255));
	renderer.AddGradientPoint ( 1.0000, utils::Color (255, 255, 255, 255));
	/*/
	renderer.AddGradientPoint (-1.0000, utils::Color (  0,   0,   0, 255));
	renderer.AddGradientPoint (-0.9375, utils::Color (  0,   0,   0, 255));
	renderer.AddGradientPoint (-0.8750, utils::Color (216, 216, 242, 255));
	renderer.AddGradientPoint ( 0.0000, utils::Color (191, 191, 191, 255));
	renderer.AddGradientPoint ( 0.5000, utils::Color (210, 116, 125, 255));
	renderer.AddGradientPoint ( 0.7500, utils::Color (210, 113,  98, 255));
	renderer.AddGradientPoint ( 1.0000, utils::Color (255, 176, 192, 255));
	//*/
	
	Render( renderer, 4 );
}
